package com.chenliang.autetest.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.jmeter.reporters.ResultCollector;
import org.apache.jmeter.reporters.Summariser;
import org.apache.jmeter.samplers.SampleEvent;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.visualizers.Visualizer;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * @program: project-execute-service
 * @description:
 * @author: chenLiang
 * @create: 2022-12-12 18:43
 */



@Slf4j
public class InvokeResultCollector extends ResultCollector {


    public InvokeResultCollector() {
    }

    public InvokeResultCollector(Summariser summer) {
        super(summer);
    }

    @Override
    public void sampleOccurred(SampleEvent e) {
        super.sampleOccurred(e);
        SampleResult r = e.getResult();

        String response = r.getResponseDataAsString();
        String requestSql = r.getSamplerData();
        log.info("当前sql-->{},返回值是:{}",requestSql,response);
        if (!StringUtils.isEmpty(response)){
            List<String> list = Arrays.asList(response.split("(\n)"));
            System.out.println(list);
            // TODO: 2022/12/13 需要具体处理
        }

    }

}
